#include <iostream>
#include <list>
#include <set>
#include <stack>
static std::set<int> prime{2,3,5,7,11,13,17,19,23,29,31,37,41};
void f(std::list<int> l, std::list<int> r)
{
    if(r.size()==0)
    {
        if(prime.find(l.front()+l.back())==prime.end())
            return;
        int count = 0;
        for(std::list<int>::iterator ite = l.begin(); ite!= l.end(); ite++)
        {
            if(++count!=l.size())
                std::cout<<*ite<<" ";
            else
                std::cout<<*ite<<std::endl;
        }
    }else{
        int last = l.back();
        std::list<int> tr,tl;


        for(std::list<int>::iterator ite = r.begin(); ite!=r.end(); ite++)
        {
            if(prime.find(*ite+last)!=prime.end())
            {
                tl=l;
                tl.push_back(*ite);
                tr=r;
                tr.remove(*ite);
                f(tl,tr);
            }
        }
    }
}
inline bool isPrime(int a, int b)
{
    if(prime.find(a+b)!=prime.end())
        return true;
    return false;
}
void dfs(int step, int max, bool *visit, int *path)
{
    if(step==max)
    {
        if(isPrime(path[max-1], 1))
        {
            for(int i = 0; i < max; i++)
            {
                if(i<max-1)std::cout<<path[i]<<" ";
                else
                    std::cout<<path[i]<<std::endl;
            }
        }
    }else
    {
        for(int i = 2; i <= max; i++)
        {
            if(!visit[i])
            {
                if(isPrime(i, path[step-1]))
                {
                    path[step]=i;
                    visit[i]=true;
                    dfs(step+1, max, visit, path);
                    visit[i]=false;
                }
            }
        }
    }
}
int main(int argc, char *argv[])
{
    int n;
    int i = 0;
    while (std::cin>>n) {
        if(n==1){
            printf("Case %d:\n1", ++i);
            continue;
        }
        bool visit[21]={0};
        int path[22]={0};
        printf("Case %d:\n", ++i);
        visit[1]=1;
        path[0]=1;
        dfs(1,n,visit,path);
        std::cout<<std::endl;
    }
}
